package com.kaishengit.dao;

import java.util.List;

import org.hibernate.Query;
import org.springframework.stereotype.Repository;

import com.kaishengit.pojo.Project;
import com.kaishengit.pojo.Trend;

@Repository
@SuppressWarnings("unchecked")
public class TrendDao extends BaseDao<Trend, Integer> {

	public List<Trend> findByProject(Project project) {
		Query query = getSession().createQuery(
				"from Trend where project=:project order by id desc");
		query.setParameter("project", project);
		return query.list();
	}

	public long count(int id, Project project) {
		Query query = getSession().createQuery(
				"SELECT COUNT(*) FROM Trend WHERE project=:project AND id>:id");
		query.setParameter("project", project);
		query.setParameter("id", id);
		return (Long) query.uniqueResult();
	}

	public List<Trend> findItIdProject(int id, Project project) {
		Query query = getSession()
				.createQuery(
						"from Trend where project=:project and id>:id order by id desc");
		query.setParameter("project", project);
		query.setParameter("id", id);
		return query.list();
	}

}
